package com.backend.aptimgview.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.backend.common.annotation.Log;
import com.backend.common.core.controller.BaseController;
import com.backend.common.core.domain.AjaxResult;
import com.backend.common.enums.BusinessType;
import com.backend.aptimgview.domain.AptimgView;
import com.backend.aptimgview.service.IAptimgViewService;
import com.backend.common.utils.poi.ExcelUtil;
import com.backend.common.core.page.TableDataInfo;

/**
 * 公寓图片管理Controller
 *
 * @author fusi
 * @date 2024-10-06
 */
@RestController
@RequestMapping("/aptimgview/aptimgview")
public class AptimgViewController extends BaseController
{
    @Autowired
    private IAptimgViewService aptimgViewService;

    /**
     * 查询公寓图片管理列表
     */
    @PreAuthorize("@ss.hasPermi('aptimgview:aptimgview:list')")
    @GetMapping("/list")
    public TableDataInfo list(AptimgView aptimgView)
    {
        startPage();
        List<AptimgView> list = aptimgViewService.selectAptimgViewList(aptimgView);
        return getDataTable(list);
    }

    /**
     * 导出公寓图片管理列表
     */
    @PreAuthorize("@ss.hasPermi('aptimgview:aptimgview:export')")
    @Log(title = "公寓图片管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AptimgView aptimgView)
    {
        List<AptimgView> list = aptimgViewService.selectAptimgViewList(aptimgView);
        ExcelUtil<AptimgView> util = new ExcelUtil<AptimgView>(AptimgView.class);
        util.exportExcel(response, list, "公寓图片管理数据");
    }

    /**
     * 获取公寓图片管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('aptimgview:aptimgview:query')")
    @GetMapping(value = "/imageApartmentId/{imageApartmentId}")
    public AjaxResult getInfoByImageApartmentId(@PathVariable("imageApartmentId") Long imageApartmentId)
    {
        return success(aptimgViewService.selectAptimgViewByImageApartmentId(imageApartmentId));
    }


    @PreAuthorize("@ss.hasPermi('aptimgview:aptimgview:query')")
    @GetMapping(value = "/{apartmentId}")
    public AjaxResult getApartmentByApartmentId(@PathVariable("apartmentId") Long apartmentId)
    {
        return success(aptimgViewService.selectAptimgViewByApartmentId(apartmentId));
    }

    /**
     * 新增公寓图片管理
     */
    @PreAuthorize("@ss.hasPermi('aptimgview:aptimgview:add')")
    @Log(title = "公寓图片管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AptimgView aptimgView)
    {
        return toAjax(aptimgViewService.insertAptimgView(aptimgView));
    }

    /**
     * 修改公寓图片管理
     */
    @PreAuthorize("@ss.hasPermi('aptimgview:aptimgview:edit')")
    @Log(title = "公寓图片管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AptimgView aptimgView)
    {
        return toAjax(aptimgViewService.updateAptimgView(aptimgView));
    }

    /**
     * 删除公寓图片管理
     */
    @PreAuthorize("@ss.hasPermi('aptimgview:aptimgview:remove')")
    @Log(title = "公寓图片管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{imageApartmentIds}")
    public AjaxResult remove(@PathVariable Long[] imageApartmentIds)
    {
        return toAjax(aptimgViewService.deleteAptimgViews(imageApartmentIds));
    }
}
